import axios from "axios"
import { useToast } from "../utils/index"

const instance = axios.create({
  baseURL: 'http://kumanxuan1.f3322.net:8881/cms',
  timeout: 5000,
})

instance.interceptors.request.use(function (config) {
  return config
}, function (error) {
  return Promise.reject(error)
})

instance.interceptors.response.use(function (res) {
  if (res.data.code != 0 && res.data.code != 400 && res.data.code != 407) {
    useToast(res.data.message, 'danger', 5000)
    return false
  }
  return res.data
}, function (error) {
  useToast(error.message, 'danger')
  return Promise.reject(error)
})

export default instance